package com.dorm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dorm.entity.Building;
import com.dorm.mapper.BuildingMapper;
import com.dorm.service.BuildingService;
import org.springframework.stereotype.Service;

/**
 * 宿舍楼服务实现类
 */
@Service
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> implements BuildingService {

    @Override
    public Page<Building> pageQuery(Integer pageNum, Integer pageSize, String buildingNo, String buildingName) {
        Page<Building> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Building> wrapper = new LambdaQueryWrapper<>();
        
        if (buildingNo != null && !buildingNo.isEmpty()) {
            wrapper.like(Building::getBuildingNo, buildingNo);
        }
        if (buildingName != null && !buildingName.isEmpty()) {
            wrapper.like(Building::getBuildingName, buildingName);
        }
        
        wrapper.orderByDesc(Building::getCreateTime);
        return page(page, wrapper);
    }
}

